package com.jml.强软弱虚引用;


import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;

/**
 * @author:jml
 * @date: 2019/5/8 16:49
 * @description：
 */
public class 虚引用 {

    public static void main(String[] args) {
        User o1 = new User();
        o1.setName("xxxxx");
        ReferenceQueue<User> referenceQueue = new ReferenceQueue();
        PhantomReference<User> phantomReference = new PhantomReference<>(o1,referenceQueue);
        System.out.println(o1);
        System.out.println(phantomReference.get());
        System.out.println(referenceQueue.poll());
        System.out.println("==========================");
        o1=null;
        System.gc();
        System.out.println(o1);
        System.out.println(phantomReference.get());
    //    System.out.println(referenceQueue.poll());
        System.out.println(referenceQueue.poll().get().getName());

    }
}
